<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>jor1k: OpenRISC OR1K Javascript Emulator Running Linux With Network Support</title>
        <meta name="keywords" content="opencore, emulation, or1000, javascript, linux">
        <meta name="author" content="Sebastian Macke">
        <link rel="stylesheet" href="css/default.css">
    </head>
    <body onload="Start()">
    <canvas id="fbfullscreen" width="640" height="400" style="width: 0px; height: 0px;">
        Framebuffer uses canvas
    </canvas>
    <div class="heading">
    <h1>jor1k: OpenRISC OR1K Javascript Emulator Running Linux With Network Support</h1>
    </div>
    <div class="windows">
        <table>
            <tr>
                <td style="vertical-align: top">
                    <table>
                    <tr><td>
                    <table id="tty" class="terminal" cellpadding="0" cellspacing="0">
                    </table>
                    </td></tr>
                    <tr><td>
                    <span style="float: left" >
                    <form style="display: inline;">
                        <select id="fpsselect" onchange='jor1k.framebuffer.SetFPS(this.options[this.selectedIndex].value)'>
                            <option value="0">0 FPS</option>
                            <option value="5"> 5 FPS</option>
                            <option value="10" selected>10 FPS </option>
                            <option value="20">20 FPS</option>
                            <option value="30">30 FPS</option>
                        </select>
                    </form>
                    <input type="text" id="loadPath" style="height: 20px;" value="/home/user" />
                    <label>
                        <img src="images/upload.png" width="20px" height="20px" title="Upload to folder" />
                        <input type="file" id="files" style="visibility:hidden;width:1px; height:1px;" name="files[]" onchange='OnUploadFiles(this.files)' multiple />
                    </label>
                    <img src="images/tar.png" width="20px" height="20px"  onclick='jor1k.fs.TAR(document.getElementById("loadPath").value)' title="Download of folder" />
                    <img src="images/sync.png" width="20px" height="20px"  onclick='jor1k.fs.Sync("home/user")' title="Sync with server" />
                    <img src="images/fullscreen.png" width="20px" height="20px"  onclick='Fullscreen()' title="Windowed fullscreen of framebuffer" />
                    <textarea style="height: 20px;" type=text cols="5" rows="1" id="clipboard">clipb</textarea>
                    <input type="checkbox" onclick='jor1k.sound.Enabled(this.checked)'>Audio
                    </span>
                    <span id="stats" style="float: right"></span>
                    </td></tr>
                    </table>

                </td>
                <td style="vertical-align: top">
                    <canvas id="fb" class="screen" width="640" height="400">
                        Framebuffer uses canvas
                    </canvas>
                </td>
            </tr>
        </table>
       
        </div>
        <div class="infobox">
            <h3>Links</h3>
            <ul>
                <li><a href="compile.html">Edit, compile and run</a> C code in your browser</li>
                <li><a href="https://github.com/s-macke/jor1k/wiki/Explore-the-emulator">Explore the emulator</a> wiki page</li>
                <li><a href="http://www.benjamincburns.com/2013/11/10/jor1k-ethmac-support.html">Ben's blog post about network support</a></li>
                <li><a href="https://github.com/s-macke/jor1k/">Project</a> page at github</li>
                <li><a href="https://github.com/s-macke/jor1k/issues">Emulator Bugtracker</a> to report any emulator issues or feature requests</li>
                <li><a href="https://github.com/benjamincburns/websockproxy/issues">Networking Bugtracker</a> to report network outages or other problems related to the demo network</li>
                <li><a href="https://github.com/s-macke/jor1k/wiki">Wiki</a> containing more detailed descriptions</li>
                <li><a href="http://openrisc.io">Official site</a> of the openrisc project</li>
            </ul>

            <h3>Developer and contributors</h3>
            <ul>
                <li class="contributor">
                    <ul>
                        <li class="contributor-info">Main developer - Sebastian Macke <a href="https://simulationcorner.net/">simulationcorner.net</a></li>
                    </ul>
                </li>
                <li class="contributor">
                    <ul>
                        <li class="contributor-info">Network support - Ben Burns <a href="https://www.benjamincburns.com">benjamincburns.com</a></li>
                    </ul>
                </li>
                <li class="contributor">
                    <ul>
                        <li class="contributor-info">Gerard Braad <a href="https://gbraad.nl">gbraad.nl</a></li>
                    </ul>
                </li>
                <li class="contributor">
                    <ul>
                        <li class="contributor-info">Compilation Demo - Neelabh Gupta</li>
                    </ul>
                </li>
                <li class="contributor">
                    <ul>
                        <li class="contributor-info">Compilation Demo and UART support - Lawrence Angrave</li>
                    </ul>
                </li>

            </ul>

        </div>

    <script src="jor1k-master-min.js"></script> 

<script>
var Jor1k = require("Jor1k");
var LinuxTerm = require("LinuxTerm");

function Fullscreen()
{
    document.body.style.margin = '0px';
    window.onresize = function(event) {
        var w = window,
        d = document,
        e = d.documentElement,
        g = d.getElementsByTagName('body')[0],
        x = w.innerWidth || e.clientWidth || g.clientWidth,
        y = w.innerHeight|| e.clientHeight|| g.clientHeight;

        var d = x/y;
        if (d > 1.6) x = y*1.6; else y = x/1.6;

        var fb = document.getElementById("fbfullscreen");
        fb.style.width = "" + x + "px";
        fb.style.height = "" + y + "px";
};
    window.onresize();
    jor1k.framebuffer.Init("fbfullscreen");
}


function OnUploadFiles(files)
{
    var path = document.getElementById("loadPath").value;
    for (var i = 0, f; f = files[i]; i++) {
        jor1k.fs.UploadExternalFile(path, f);
    }
}

function RandomString(length) {
    var chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var result = '';
    for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
    return result;
}

// from https://css-tricks.com/snippets/javascript/get-url-variables/
function getQueryVariable(variable)
{
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return decodeURIComponent(pair[1]);}
       }
       return(false);
}

function Start() {

    var pushState = false, loadUserData = false;
    var userid = getQueryVariable("user");
    if (userid == false) {
       userid = RandomString(10);
       pushState = true;
    } else {
       loadUserData = true;
    }
    // allow specifying relay URL via querystring
    var relayURL = getQueryVariable("relayURL")
    if (relayURL == false) {
        relayURL = "wss://relay.widgetry.org/";
        pushState = true;
    }

    jor1kparameters = {
        path: "../openrisc-sys/",
        system: {
            kernelURL: "kernel/vmlinux.bin.bz2", // kernel image
            memorysize: 32, // in MB, must be a power of two
            cpu: "asm", // short name for the cpu to use
            ncores: 1,
        },
        fs: {
            basefsURL: "basefs.json", // json file with the basic filesystem configuration.
            extendedfsURL: "fs.json", // json file with extended filesystem informations. Loaded after the basic filesystem has been loaded.
            earlyload: [], // list of files which should be loaded immediately after they appear in the filesystem
            lazyloadimages: [
            ] // list of automatically loaded images after the basic filesystem has been loaded
	},

        term: new LinuxTerm("tty"), // canvas id for the terminal
        fbid: "fb",                // canvas id for the framebuffer
        clipboardid: "clipboard",  // input id for the clipboard
        statsid: "stats",          // object id for the statistics test
        fps: 10, // update interval of framebuffer
        relayURL: relayURL, // relay url for the network
        userid: userid, // unique user id string. Empty, choosen randomly, from a url, or from a cookie.
        syncURL: "//jor1k.com/sync/upload.php" // url to sync a certain folder
    }

    // --------------------------------------------------------
    if (loadUserData)
        jor1kparameters.fs.lazyloadimages.push("sync/tarballs/"+userid+".tar.bz2");

    var nCores = getQueryVariable("n");
    if (nCores != false) {
       jor1kparameters.system.ncores = nCores;
    } else {
       pushState = true;
    }
    var cpu = getQueryVariable("cpu");
    if (cpu != false) {
       jor1kparameters.system.cpu = cpu;
       if (jor1kparameters.system.cpu == "smp") {
             console.log("Load smp kernel");
             jor1kparameters.system.kernelURL = "kernel/vmlinuxsmp.bin.bz2";
       }
    } else {
       pushState = true;
    }
    if (pushState) {
        window.history.pushState([], "", "?user="+encodeURIComponent(jor1kparameters.userid)+"&cpu="+encodeURIComponent(jor1kparameters.system.cpu)+"&n="+encodeURIComponent(jor1kparameters.system.ncores)+"&relayURL="+encodeURIComponent(relayURL));
    }

    // --------------------------------------------------------

    jor1k = new Jor1k(jor1kparameters);

}
</script>

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-44129312-1', 'auto');
  ga('send', 'pageview');
</script>


<div id="console">
	
</div>

    </body>
</html>
